/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t_sqlserver_envchange_token.c                      */
/*  NOTE      =                                                    */
/*  DATE      = 2014/11/27 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>
#include <sqlserver/sqlserver_token.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x01\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case2(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x01\x01\x65\x00\x01\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case3(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x03\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_STRING_EQUAL(p_charset, "e");

    frfree(p_charset);
    bytebuff_free(&p_st_data);
    return;

}

static void __case4(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x05\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case5(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x05\x01\x65\x00\x01\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case6(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x07\x01\x65\x01\x65\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case7(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x08\x01\x65\x01\x65\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case8(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x08\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case9(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x08\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case10(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x02\x00\x09\x01\x01", 5);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case11(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x09\x00\x01\x65\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case12(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x09\x00\x01\x65\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case13(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x0D\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case14(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x0D\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case15(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case16(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case17(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case18(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x03\x00\x12\x00\x00\x65", 6);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case19(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x14\x02\x00\x65\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);

    return;
}

static void __case20(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_YES;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x14\x02\x00\x65\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case21(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x01\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case22(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x01\x01\x65\x00\x01\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case23(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x03\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_STRING_EQUAL(p_charset, "e");

    frfree(p_charset);
    bytebuff_free(&p_st_data);
    return;

}

static void __case24(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x05\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case25(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x05\x01\x65\x00\x01\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case26(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x07\x01\x65\x01\x65\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_NULL);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_71);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case27(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x08\x01\x65\x01\x65\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case28(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x08\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case29(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x08\x01\x65\x00\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case30(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x02\x00\x09\x01\x01", 5);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;

}

static void __case31(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x09\x00\x01\x65\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case32(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x04\x00\x09\x00\x01\x65\x01", 7);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;

}

static void __case33(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x0D\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case34(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x0D\x01\x65\x00\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case35(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case36(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case37(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x07\x00\x0F\x01\x00\x00\x00\x65\x00\x01", 10);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case38(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_72;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x03\x00\x12\x00\x00\x65", 6);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_72);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

static void __case39(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_71;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x14\x02\x00\x65\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

static void __case40(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    int i_whole_flg = FR_NO;
    int i_tds_ver = MSSQL_TDS_VER_NULL;
    int i_min_tds_ver = MSSQL_TDS_VER_71;
    int i_max_tds_ver = MSSQL_TDS_VER_74;
    char *p_charset = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x05\x00\x14\x02\x00\x65\x00\x01", 8);

    i_ret = sqlserver_envchange_token(p_st_data, i_whole_flg, &i_tds_ver, &i_min_tds_ver, &i_max_tds_ver, &p_charset);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(i_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_EQUAL(i_min_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_EQUAL(i_max_tds_ver, MSSQL_TDS_VER_74);
    CU_ASSERT_PTR_NULL(p_charset);

    bytebuff_free(&p_st_data);
    return;
}

int add_suite_sqlserver_envchange_token(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sqlserver_envchange_token()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL ||
        CU_add_test(pSuite, "case8", __case8) == NULL ||
        CU_add_test(pSuite, "case9", __case9) == NULL ||
        CU_add_test(pSuite, "case10", __case10) == NULL ||
        CU_add_test(pSuite, "case11", __case11) == NULL ||
        CU_add_test(pSuite, "case12", __case12) == NULL ||
        CU_add_test(pSuite, "case13", __case13) == NULL ||
        CU_add_test(pSuite, "case14", __case14) == NULL ||
        CU_add_test(pSuite, "case15", __case15) == NULL ||
        CU_add_test(pSuite, "case16", __case16) == NULL ||
        CU_add_test(pSuite, "case17", __case17) == NULL ||
        CU_add_test(pSuite, "case18", __case18) == NULL ||
        CU_add_test(pSuite, "case19", __case19) == NULL ||
        CU_add_test(pSuite, "case20", __case20) == NULL ||
        CU_add_test(pSuite, "case21", __case21) == NULL ||
        CU_add_test(pSuite, "case22", __case22) == NULL ||
        CU_add_test(pSuite, "case23", __case23) == NULL ||
        CU_add_test(pSuite, "case24", __case24) == NULL ||
        CU_add_test(pSuite, "case25", __case25) == NULL ||
        CU_add_test(pSuite, "case26", __case26) == NULL ||
        CU_add_test(pSuite, "case27", __case27) == NULL ||
        CU_add_test(pSuite, "case28", __case28) == NULL ||
        CU_add_test(pSuite, "case29", __case29) == NULL ||
        CU_add_test(pSuite, "case30", __case30) == NULL ||
        CU_add_test(pSuite, "case31", __case31) == NULL ||
        CU_add_test(pSuite, "case32", __case32) == NULL ||
        CU_add_test(pSuite, "case33", __case33) == NULL ||
        CU_add_test(pSuite, "case34", __case34) == NULL ||
        CU_add_test(pSuite, "case35", __case35) == NULL ||
        CU_add_test(pSuite, "case36", __case36) == NULL ||
        CU_add_test(pSuite, "case37", __case37) == NULL ||
        CU_add_test(pSuite, "case38", __case38) == NULL ||
        CU_add_test(pSuite, "case39", __case39) == NULL ||
        CU_add_test(pSuite, "case40", __case40) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
